Open
Conversation
tiemo0708
reviewed
Nov 20, 2024
Comment on lines
+35
to
+44
| for (int i = 0; i < NUMBERS_SIZE; i++) { | ||
| boolean isStrike = computerNumbers.get(i).equals(playerNumbers.get(i)); | ||
| boolean isBall = !isStrike && computerNumbers.contains(playerNumbers.get(i)); | ||
| if (isStrike) { | ||
| strikes++; | ||
| } | ||
| if (isBall) { | ||
| balls++; | ||
| } | ||
| } |
There was a problem hiding this comment.
해당 클래스에 스트라이크, 볼 판정 로직이 있어도 될지 궁금합니다
Comment on lines
+6
to
+7
| RESTART("1", true), | ||
| QUIT("2", false); |
| validateNumber(number); | ||
| return number; | ||
| } catch (NumberFormatException e) { | ||
| throw new IllegalArgumentException("입력값은 숫자여야 합니다."); |
|
|
||
| public class InputView { | ||
|
|
||
| public String getNumber() { |
Comment on lines
+13
to
+23
| private List<Integer> parse(String input) { | ||
| List<String> items = List.of(input.split("")); | ||
| List<Integer> numbers = new ArrayList<>(); | ||
| for (String item : items) { | ||
| int number = parseNumber(item); | ||
| numbers.add(number); | ||
| } | ||
| validateNumbers(numbers); | ||
| return numbers; | ||
| } | ||
|
|
jiffyin7
reviewed
Nov 20, 2024
Comment on lines
+33
to
+38
| boolean isFinish = false; | ||
| ComputerNumbers computerNumbers = init(); | ||
| while (!isFinish) { | ||
| PlayerNumbers playerNumbers = input(); | ||
| isFinish = result(computerNumbers, playerNumbers); | ||
| } |
| private final List<Integer> computerNumbers; | ||
|
|
||
| public ComputerNumbers() { | ||
| this.computerNumbers = createRandomNumbers(); |
There was a problem hiding this comment.
생성자에서 온전히 생성만을 담당하기 위해
생성로직을 분리하는것은 어떨까요?
| } | ||
|
|
||
| public boolean isCorrect() { | ||
| return strikes == 3; |
dompoo
reviewed
Nov 20, 2024
Comment on lines
+8
to
+11
| public final static String WHITE_SPACE = " "; | ||
| public final static String STRIKE = "%d스트라이크"; | ||
| public final static String BALL = "%d볼"; | ||
| public final static String NOTHING = "낫싱"; |
There was a problem hiding this comment.
이 상수들은 위 상수들과는 조금 다르게 출력에 초점을 맞추고 있는 상수들이에요. 상수도 분리해서 관리하면 어떨까요?
Comment on lines
+27
to
+28
| } catch (IllegalArgumentException e) { | ||
| throw new IllegalArgumentException(e.getMessage()); |
There was a problem hiding this comment.
어차피 IllegalArgumentException으로 받아서 똑같은 메시지로 다시 던질거면 여기서 try-catch를 왜 사용하신지 궁금해요!
Comment on lines
+24
to
+25
| play(); | ||
| isContinue = restart(); |
There was a problem hiding this comment.
메서드가 아주 보기 좋게 잘려있으니 이 둘을 서비스나 다른 컨트롤러로 분리하기 아주 좋아보입니다. ㅎㅎ.... (츄릅)
어떻게 생각하세요?
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| public class PlayerNumbers { |
There was a problem hiding this comment.
PlayerNumber와 ComputerNumeber가 비슷한 기능을 수행하는 부분이 있어서, 추상클래스로 묶으면 검증등의 로직을 빼볼 수 있을 것 같아요!
|
|
||
| import static camp.nextstep.edu.missionutils.Console.readLine; | ||
|
|
||
| public class InputView { |
There was a problem hiding this comment.
InputView에서 좀 더 적극적으로 List나 boolean을 제공하지 않고, String만 제공하는지 궁금합니다! 너무 역할이 없는 것 같아요.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
숫자 야구 미션
고민했던 부분
패키지 구조
classDiagram direction TB class baseball { Application } baseball "1" --> "1" common baseball "1" --> "1" config baseball "1" --> "1" controller baseball "1" --> "1" model baseball "1" --> "1" view class common { <<package>> } common --> constant class constant { Constants } class config { <<package>> GameConfig } class controller { <<package>> GameController } class model { <<package>> } model --> domain class domain { ComputerNumbers GameMenu PlayerNumbers Result } class view { <<package>> InputView OutputView }클래스 다이어그램
classDiagram direction BT class Application { + main(String[]) void + Application() } class ComputerNumbers { - createRandomNumbers() List~Integer~ + compare(PlayerNumbers) Result + ComputerNumbers() } class Constants { + Constants() } class GameConfig { + GameConfig() GameController gameComputer } class GameController { - result(ComputerNumbers, PlayerNumbers) boolean - input() PlayerNumbers - init() ComputerNumbers - restart() boolean - play() void - finish() void + start() void + GameController(InputView, OutputView) } class GameMenu { <<enumeration>> + valueOf(String) GameMenu + from(String) boolean + values() GameMenu[] - GameMenu(String, boolean) boolean countinue - boolean countinue } class InputView { + askRestart() String + InputView() String number } class OutputView { + printRestartPrompt() void + printNumberPrompt() void + printFinishMessage() void + printResultMessage(String) void + printStartMessage() void + printErrorMessage(String) void + OutputView() } class PlayerNumbers { - parse(String) List~Integer~ - parseNumber(String) int - validateNumber(int) int - validateNumbers(List~Integer~) void + PlayerNumbers(String) List~Integer~ playerNumbers - List~Integer~ playerNumbers } class Result { + toString() String + Result(int, int) boolean correct } GameConfig "1" *--> "gameController 1" GameController GameConfig "1" *--> "inputView 1" InputView GameConfig "1" *--> "outputView 1" OutputView GameController "1" *--> "inputView 1" InputView GameController "1" *--> "outputView 1" OutputView플로우 차트
graph TD A[게임 시작] --> B[시작 메시지 출력] B --> C{게임을 계속 진행할까요?} C -->|예| D[컴퓨터 숫자 초기화] D --> E{게임 종료 여부 확인} E -->|아니오| F[플레이어 숫자 입력] F --> G[결과 비교] G --> H[결과 메시지 출력] H --> E E -->|예| I[종료 메시지 출력] I --> J{다시 시작할까요?} J -->|예| C J -->|아니오| K[게임 종료]